package com.pactera.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;

public class ReqUtil {

	public static String getReqMessage(String baseUrl,
			HashMap<String, String> reqdatas) throws IllegalArgumentException,
			IllegalAccessException, UnsupportedEncodingException {
		StringBuilder sb = new StringBuilder(baseUrl);
		if (baseUrl.contains("?")) {
			sb.append("&");
		} else {
			sb.append("?");
		}
		Set<Entry<String, String>> rqs = reqdatas.entrySet();
		Iterator<Entry<String, String>> iess = rqs.iterator();
		while (iess.hasNext()) {
			Entry<String, String> ess = iess.next();
			sb.append(URLEncoder.encode(ess.getKey(), "utf-8")).append("=")
					.append(URLEncoder.encode(ess.getValue(), "utf-8"))
					.append("&");
		}
		sb.deleteCharAt(sb.length() - 1);
		return sb.toString();
	}
}
